#ifndef ILLIB_System_H_
#define ILLIB_System_H_

#include <stdint.h>
#include <stddef.h>
#define alignof(t) __alignof(t)

namespace illib {
	namespace System {
		class Memory {
		private:
			Memory(const Memory &other);
			Memory();
		protected:
			size_t blockSize_;
			uint8_t *block_;
		public:
			Memory(uint8_t* block, size_t blockSize);
			bool contains(void* ptr, size_t size);
			~Memory();
			uint8_t * start() {
				return block_;
			}
			uint8_t * end() {
				return block_+blockSize_;
			}
			size_t size() {
				return blockSize_;
			}
		};
		class Allocator{
		private:
			Allocator(const Allocator &other);
		protected:
			size_t pagesize_;
			static Allocator * instance_;
			friend Allocator & allocator();
			friend void allocator(Allocator &);
		public:
			Allocator() :
				pagesize_(4096)

			{
				instance_ = this;
			}
			uint8_t* allocate(size_t size, uint8_t align);
			void release(void* ptr, size_t size);
			size_t pagesize();
			void initialize(size_t pagesize);
		};
		extern Allocator& allocator();
		extern void allocator(Allocator& allocator);
		extern size_t align(size_t size, uint8_t alignment);
		template<typename T> size_t align(size_t size){
			return align(size, alignof(T));
		}
		template<typename T> size_t align(){
			return align(sizeof(T), alignof(T));
		}
		enum Endiannes {
			big, little
		};
		extern const Endiannes endianness;
	}
}

#endif /* ILLIB_System_H_ */
